home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3645 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with arrays
  5. Date: Tue, 30 Jan 96 13:52:42 GMT
  6. Organization: none
  7. Message-ID: <823009962snz@genesis.demon.co.uk>
  8. References: <4ejtia$6id@sifon.cc.mcgill.ca> <4el775$g6i@phcoms4.seri.philips.nl>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4el775$g6i@phcoms4.seri.philips.nl>
  15.            keijsers@sce.philips.nl "Marc Keijsers" writes:
  16.  
  17. >>
  18. >>       I'm currently writing a program using tries to store words. For bulding
  19. > my trie, I have defined the following struct:
  20. >>
  21. >>typedef struct nodebox NODEBOX, *TRIE
  22. >>
  23. >>struct nodebox{
  24. >>{      int letters[100];
  25. >>       TRIE subtree[100];
  26. >>};
  27. >>
  28. >>Then, I declare variables as tries in certain functions. But here's the
  29. > problem: before inserting any letter in the trie, I expect the
  30. >>
  31. >>elements in the array letters to be all zeros( '\0' ) like in a normal empty
  32. > >array. But instead, the elements of this arrays are weird 
  33. >
  34. >(Please, Please, don't use the word trIe if you mean tree. It makes
  35. >this story utterly confusing.)
  36.  
  37. A Trie is a particular form of tree used in things like dictionaries. I
  38. don't see any evidence that the term was misused here.
  39.  
  40. >This is completely NORMAL. If you declare an array, its values are
  41. >undefined. You will have to write a routine which initialises your
  42. >structure with '/0' (plain '0' will do also).
  43.  
  44. Static/global variables are always initialised when they are created (at
  45. program startup in that case), local (auto) function variables are not
  46. initialised unless given an explicit initialiser in the definition. This
  47. is true whatever the type of the variable.
  48.  
  49. >>numbers like 25678. It bothers me since I assume that they are '\0' in my
  50. > >insert function. I really don't know what's going wrong.
  51. >>
  52. >>If you have any idea or solutions, I'd be very graceful if you could e-mail
  53. > me; >I'm stuck.
  54.  
  55. Don't assume that they are '\0' in your code, initialise themn when you
  56. define them or when you first use them.
  57.  
  58. -- 
  59. -----------------------------------------
  60. Lawrence Kirby | fred@genesis.demon.co.uk
  61. Wilts, England | 70734.126@compuserve.com
  62. -----------------------------------------
  63.